<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="@{/}">
    <meta charset="UTF-8">
    <title>查询类型页面</title>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <script src="js/jquery.min.js"></script>
    <script type="text/javascript" th:inline="javascript">
        function deleteType(tid) {
            $.ajax(
                {
                    //请求路径，要注意的是url和th:inline="javascript"
                    url: [[@{/type/deleteType
                }
        ]],
            //请求类型
            type : "post",
                //data表示发送的数据
                data
        :
            {
                id : tid
            }
        ,
            //成功响应的结果
            success : function (obj) {//obj响应数据
                if (obj == "no") {
                    alert("该类型下有商品不允许删除！");
                } else {
                    if (window.confirm("真的删除该类型吗？")) {
                        //获取路径
                        var pathName = window.document.location.pathname;
                        //截取，得到项目名称
                        var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
                        window.location.href = projectName + obj;
                    }
                }
            }
        ,
            error : function () {
                alert("处理异常！");
            }
        }
        )
            ;
        }
    </script>
</head>
<body>
    <!-- 加载header.html -->
    <div th:include="admin/header"></div>
    <br><br><br>
    <section class="home-section">
        <div class="home-content">
            <i class='bx bx-menu' ></i>
            <span class="text">管理员界面</span>
        </div>
        <div class="test">
            <div class="container">
                <div class="panel panel-primary" style="border-radius: 0px 0px 25px 25px">
                    <div class="panel-heading" style="background-color: rgba(85,81,133,0.6);">
                        <h3 class="panel-title">商品类型列表</h3>
                    </div>
                    <div class="panel-body">
                        <div class="table table-responsive">
                            <table class="table  table-hover table-bordered  	table-striped">
                                <tbody class="text-center">
                                <tr>
                                    <th style="text-align: center">类型ID</th>
                                    <th style="text-align: center" >类型名称</th>
                                    <th style="text-align: center">操作</th>
                                </tr>
                                <tr th:each="gty:${allTypes}">
                                    <td th:text="${gty.id}"></td>
                                    <td th:text="${gty.typename}"></td>
                                    <td>
                                        <button type="button" class="btn btn-default btn-xm" data-toggle="modal" data-target="#myModal">
                                        <a th:href="'javascript:deleteType(' + ${gty.id} + ')'">删除</a>
                                        </button>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="3" align="right">
                                        <ul class="pagination">
                                            <li><a>第<span th:text="${currentPage}"></span>页</a></li>
                                            <li><a>共<span th:text="${totalPage}"></span>页</a></li>
                                            <li>
											<span th:if="${currentPage} != 1">
												<a th:href="'type/selectTypeDelete?currentPage=' + ${currentPage - 1}">上一页</a>
											</span>
                                                <span th:if="${currentPage} != ${totalPage}">
												<a th:href="'type/selectTypeDelete?currentPage=' + ${currentPage + 1}">下一页</a>
											</span>
                                            </li>
                                        </ul>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

</body>
</html>
